<!doctype html>
<html>
    <head>
        <meta charset="utf-8" />
        <meta
            name="viewport"
            content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"
        />
        <meta
            name="format-detection"
            content="telephone=no,email=no,date=no,address=no"
        />
        <title>Hello APP</title>
        <link rel="stylesheet" type="text/css" href="../css/aui.css" />
        <script src="../script/jquery.js"></script>
        <script src="../CommonTool/commonNetWork.js"></script>
        <style>
            body {
                background-color: #03a9f4;
            }

            #frm-container {
                margin: 5px auto;
                width: 83%;
                height: 100%;
                border-radius: 20px;
                border: 2px solid white;
                padding: 5px 10px;
                background: white;
            }

            #footer {
                background: none;
                position: absolute;
                bottom: 0;
            }
        </style>
    </head>

    <body>
        <div id="frm-container" class="aui-content-padded">
            <div
                class="aui-tab aui-margin-t-10 aui-margin-b-5 aui-font-size-18"
            >
                <div style="color: #03a9f4; margin: 0 auto">用户注册</div>
            </div>
            <div
                class="aui-hr"
                style="
                    width: 90%;
                    margin: 0 auto;
                    border-top: 0.05rem solid #03a9f4;
                "
            ></div>
            <section class="aui-content-padded"></section>
            <section class="aui-content-padded">
                <div
                    class="aui-searchbar"
                    id="search"
                    style="
                        margin-bottom: 1rem;
                        background-color: #ffffff;
                        width: 100%;
                    "
                >
                    <div
                        class="aui-searchbar-input aui-border-radius"
                        style="
                            margin: 0rem;
                            height: 1.8rem;
                            border: 1px solid #459bde;
                            background-color: transparent;
                        "
                    >
                        <div
                            class="aui-iconfont aui-icon-my"
                            style="
                                width: 16px;
                                font-size: 12px;
                                margin-top: 3px;
                            "
                        ></div>
                        <div
                            style="
                                margin-top: 7px;
                                margin-right: 8px;
                                height: 21px;
                                width: 1px;
                                border-left: 1px #459bde solid;
                            "
                        ></div>
                        <input
                            style="margin-top: 3px; font-size: 0.8rem"
                            placeholder="请输入用户名"
                            id="login_username"
                        />
                        <div class="aui-searchbar-clear-btn">
                            <i class="aui-iconfont aui-icon-close"></i>
                        </div>
                    </div>
                    <div class="aui-searchbar-btn" tapmode>取消</div>
                </div>
                <!-- <div class="aui-searchbar" id="search" style="margin-bottom:1rem;background-color:#ffffff;width:100%">
                <div class="aui-searchbar-input aui-border-radius" style="width:60%;margin:0rem;height:1.8rem;border:1px solid #459bde;background-color:transparent;">
                    <div class="aui-iconfont aui-icon-mail" style="width:16px;font-size:12px;margin-top:3px"></div>
                    <div style="margin-top:7px;margin-right:8px;height:21px; width:1px; border-left:1px #459bde solid"></div>
                    <input style="margin-top:3px;font-size:0.8rem" type="number" placeholder="短信验证码" id="msgcode">
                    <div class="aui-searchbar-clear-btn">
                        <i class="aui-iconfont aui-icon-close"></i>
                    </div>
                </div>
                <div id="sendValidcode" class="aui-btn aui-btn-block  aui-btn-sm aui-font-size-12" style="color:#ffffff;text-align:center;width:35%;margin-left:5%;background-color:#03a9f4" tapmode onclick="sms();">获取验证码</div>
                <div class="aui-searchbar-btn" tapmode>取消</div>
            </div> -->

                <div
                    class="aui-searchbar"
                    id="search"
                    style="
                        margin-bottom: 1rem;
                        background-color: #ffffff;
                        width: 100%;
                    "
                >
                    <div
                        class="aui-searchbar-input aui-border-radius"
                        style="
                            margin: 0rem;
                            height: 1.8rem;
                            border: 1px solid #459bde;
                            background-color: transparent;
                        "
                    >
                        <div
                            class="aui-iconfont aui-icon-lock"
                            style="
                                width: 16px;
                                font-size: 12px;
                                margin-top: 3px;
                            "
                        ></div>
                        <div
                            style="
                                margin-top: 7px;
                                margin-right: 8px;
                                height: 21px;
                                width: 1px;
                                border-left: 1px #459bde solid;
                            "
                        ></div>
                        <input
                            style="margin-top: 3px; font-size: 0.8rem"
                            type="password"
                            placeholder="请输入密码（6-16位字符）"
                            id="login_password"
                        />
                        <div class="aui-searchbar-clear-btn">
                            <i class="aui-iconfont aui-icon-close"></i>
                        </div>
                    </div>
                    <div class="aui-searchbar-btn" tapmode>取消</div>
                </div>
                <div
                    class="aui-searchbar"
                    id="search"
                    style="
                        margin-bottom: 1rem;
                        background-color: #ffffff;
                        width: 100%;
                    "
                >
                    <div
                        class="aui-searchbar-input aui-border-radius"
                        style="
                            margin: 0rem;
                            height: 1.8rem;
                            border: 1px solid #459bde;
                            background-color: transparent;
                        "
                    >
                        <div
                            class="aui-iconfont aui-icon-lock"
                            style="
                                width: 16px;
                                font-size: 12px;
                                margin-top: 3px;
                            "
                        ></div>
                        <div
                            style="
                                margin-top: 7px;
                                margin-right: 8px;
                                height: 21px;
                                width: 1px;
                                border-left: 1px #459bde solid;
                            "
                        ></div>
                        <input
                            style="margin-top: 3px; font-size: 0.8rem"
                            type="password"
                            placeholder="请再次输入确认密码"
                            id="login_confirm_password"
                        />
                        <div class="aui-searchbar-clear-btn">
                            <i class="aui-iconfont aui-icon-close"></i>
                        </div>
                    </div>
                    <div class="aui-searchbar-btn" tapmode>取消</div>
                </div>
                <!-- <input id="agree_user" class="aui-checkbox" type="checkbox" name="demo1" > -->
                <!--
          -->
                <!-- <span class="aui-font-size-14">阅读并同意</span>
            <span class="aui-font-size-14" style="color:#459bde" onclick="show_agreement();">用户协议</span> -->
                <div
                    class="aui-btn aui-btn-block aui-btn-info aui-btn-sm"
                    style="margin-top: 20px"
                    tapmode
                    onclick="login_register();"
                >
                    注册
                </div>
                <div
                    class="aui-content-padded aui-hide"
                    style="text-align: center"
                    id="waiting_gif"
                >
                    <img
                        src="../../image/loading_more.gif"
                        style="width: 20px; height: 20px"
                        class="aui-inline"
                    />
                </div>
                <div
                    class="aui-font-size-30"
                    style="
                        text-align: center;
                        margin-top: 0.5rem;
                        color: #459bde;
                    "
                    onclick="Direct_entry();"
                >
                    直接登录
                </div>
            </section>
            <section class="aui-content aui-margin-t-10 aui-hide" id="footer">
                <p class="aui-font-size-12 aui-text-center">第三方账号登录</p>
                <div class="aui-hr"></div>
                <div class="aui-grid" style="background: none">
                    <div class="aui-row">
                        <div class="aui-col-xs-4"></div>
                        <div class="aui-col-xs-4">
                            <i class="aui-iconfont aui-icon-wechat"></i>
                        </div>
                        <div class="aui-col-xs-4"></div>
                    </div>
                </div>
            </section>
        </div>
    </body>
    <script type="text/javascript" src="../script/api.js"></script>
    <script>
        function login_register() {
            $.ajax({
                url: CommonUrl + "/tSysUser/insert",
                method: "post",
                dataType: "json",
                contentType: "application/json",
                // contentType: 'application/x-www-form-urlencoded;charset=UTF-8',
                data: JSON.stringify({
                    code: document.getElementById("login_username").value,
                    password: document.getElementById("login_password").value,
                    confirmpassword: document.getElementById(
                        "login_confirm_password",
                    ).value,
                }),
                success: function (data) {
                    alert(JSON.parse(JSON.stringify(data.data)));
                    history.go(0);
                },
                error: function (error) {
                    alert("登录失败");
                },
            });
        }
        function Direct_entry() {
            api.openWin({
                name: "login",
                url: "./login.html",
                reload: true,
            });
        }
    </script>
    <!-- <script type="text/javascript">
    var smsVerify = null;
    var n = 0;
    var intervalID;
    apiready = function() {
        smsVerify = api.require("smsVerify");
        register();
        api.parseTapmode();
        //适配iOS7+，Android4.4+状态栏沉浸式效果，详见config文档statusBarAppearance字段
        $api.fixStatusBar($api.byId('aui-header'));
        $api.css($api.byId('frm-container'), 'height:' + api.frameHeight * 1.50 + 'px;')
    }

    function register() {
        smsVerify.register(function(ret, err) {
            if (ret.status) {
                //api.alert({msg: '注册成功'});
                console.log('注册成功');
            } else {
                // api.alert({
                //     msg: err.code + ' 注册失败'
                // });
            }
        });
    }

    function setEnable() {
        n++;
        if (n > 0 && n <= 60) {
            document.getElementById("sendValidcode").innerText = "重新发送(" + (60 - n) + "s)";
            //  document.getElementById("sendValidcode").removeEventListener("click", sms, false);
            document.getElementById("sendValidcode").disabled = true;
            document.getElementById("sendValidcode").style.backgroundColor = '#B8B8B8';
            document.getElementById("sendValidcode").style.color = '#000000';

        } else {
            document.getElementById("sendValidcode").innerText = "获取验证码";
            //document.getElementById("sendValidcode").addEventListener("click", sms, false);
            document.getElementById("sendValidcode").disabled = false;
            document.getElementById("sendValidcode").style.backgroundColor = '#03a9f4';
            document.getElementById("sendValidcode").style.color = '#ffffff';
            window.clearInterval(intervalID);
            n = 0;
        }
    }
    //获取短信验证码
    function sms() {
        if ($api.val($api.byId('login_username')).trim() == "") {
            api.toast({
                msg: "手机号或用户名不能为空",
                duration: 2000,
                location: 'bottom'
            });
            return;
        }
        if ($api.val($api.byId('login_username')).length != 11) {
            api.toast({
                msg: "手机号格式错误",
                duration: 2000,
                location: 'bottom'
            });
            return;
        }
        var phoneNum = document.getElementById("login_username").value;
        smsVerify.sms({
            phone: phoneNum,
        }, function(ret, err) {
            if (ret.status) {
                // 新增的安卓智能验证功能
                if (ret.smart == true) { // 安卓版特有功能 智能验证成功
                    api.alert({
                        msg: '智能验证成功，开发者可以为用户直接跳转到手机号验证成功之后的操作'
                    });
                } else {
                    api.alert({
                      msg: '短信发送成功'
                     });
                }
                intervalID = window.setInterval("setEnable()", 1000);
            } else {
                api.alert({
                    msg: ' 短信发送失败'
                });
            }
        });
    }

    function form_check() {
        if (!$api.byId('agree_user').checked) {
            api.toast({
                msg: "请同意用户协议！",
                duration: 2000,
                location: 'bottom'
            });
            return false;
        }

        if ($api.val($api.byId('login_username')).trim() == "") {
            api.toast({
                msg: "手机号不能为空",
                duration: 2000,
                location: 'bottom'
            });
            return false;
        }
        if ($api.val($api.byId('login_username')).length != 11) {
            api.toast({
                msg: "手机号格式错误",
                duration: 2000,
                location: 'bottom'
            });
            return false;
        }


        if ($api.val($api.byId('login_password')).trim().length == "") {
            $api.byId('login_password').focus();
            api.toast({
                msg: "密码不能为空",
                duration: 2000,
                location: 'bottom'
            });
            return false;
        }
        //保证密码是数字加字母的组合

        if ( /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$/.test($api.val($api.byId('login_password'))) == false){
            api.toast({
                msg: "密码应为字母与数字的组合",
                duration: 2000,
                location: 'bottom'
            });
            return false;
        }

        if ($api.val($api.byId('login_password')).length < 6 || $api.val($api.byId('login_password')).length > 16) {
            api.toast({
                msg: "密码长度 6 - 16 位",
                duration: 2000,
                location: 'bottom'
            });
            return false;
        }


        if ($api.val($api.byId('msgcode')).trim() == "") {
            api.toast({
                msg: '验证码不能为空',
                duration: 2000,
                location: 'bottom'
            });
            return false;
        }
        if ($api.val($api.byId('login_password')) != $api.val($api.byId('login_confirm_password'))) {
            $api.byId('login_password').focus();
            api.toast({
                msg: "两次密码不一致，请重新输入！",
                duration: 2000,
                location: 'bottom'
            });
            return false;
        }  else if (($api.byId('login_username').value.length != 0)&&($api.byId('login_password').value == $api.byId('login_confirm_password').value)){
                $api.byId('login_username').focus();
                // $api.byId('msgcode').focus();&&($api.byId('msgcode').value.length != 0)
                $api.byId('login_password').focus();
                $api.byId('login_confirm_password').focus();
                // api.toast({
                //     msg : '注册成功!请重新登录!'
                // });
                // setTimeout(function() {
                //     api.closeWin({});
                // }, 1000);
            }
    }
    function login_register() {
        if (form_check() ==false)  {
            return;
        } else {
        var phoneNum = document.getElementById("login_username").value;
        var code = document.getElementById("msgcode").value;
        smsVerify.verify({
            phone: phoneNum,
            code: code,
        }, function(ret, err) {
            if (ret.status) {
                console.log('注册验证码验证成功')
                $api.removeCls($api.byId("waiting_gif"), "aui-hide");
                // 普通登录
                api.ajax({
                    url: $api.getStorage("api_url") + '/lansys/user/passSignUp',
                    method: 'post',
                    timeout: 5,
                    data: {
                        values: {
                            uid: $api.val($api.byId('login_username')),
                            password: $api.val($api.byId('login_password')),
                            type: 'child',
                        }
                    }
                }, function(ret, err) {
                    $api.addCls($api.byId("waiting_gif"), "aui-hide");
                    if (ret) {
                        var response = JSON.stringify(ret);
                        if (ret.msg == "ok") {
                            api.openWin({  //进行用户的自定义
                                name: 'completeInfo_profile_pic',
                                url: './completeInfo/profile_pic.html',
                                pageParam: {
                                    userID: ret.id,
                                    login_user_name: $api.val($api.byId('login_username')),
                                    login_password: $api.val($api.byId('login_password')),
                                }
                            });

                        } else if (ret.msg == "err_registration_fail") {
                            api.toast({
                                msg: "手机号已注册！",
                                duration: 2000,
                                location: 'bottom'
                            });
                        }
                    } else {
                        api.toast({
                            // msg: err,
                            msg:'注册失败，请联系管理员',
                            duration: 2000,
                            location: 'bottom'
                        });
                        //console.log(JSON.stringify(err));
                    }
                });
            } else {
                api.alert({
                    msg: '短信验证码验证失败'
                });
            }
        });
    }
    }

    function show_agreement() {
        var dialogBox = api.require('dialogBox');
        dialogBox.webView({
            tapClose: true,
            path: 'widget://html/user/agreement.html',
            texts: {
                title: '用户协议',
            },
            styles: {
                bg: '#03a9f4',
                corner: 2,
                w: 880,
                h: 330,
                title: {
                    h: 40,
                    size: 20,
                    color: '#000'
                },
                upDividingLine: {
                    width: 0.5,
                    color: '#696969'
                },
                webView: {
                    h: 330,
                    bg: '#fff',
                }
            }
        }, function(ret) {
            api.alert({
                msg: JSON.stringify(ret)
            });
            if (ret.eventType == 'left') {
                var dialogBox = api.require('dialogBox');
                dialogBox.close({
                    dialogName: 'webView'
                });
            }
        });
    }

    function close_win() {
        api.closeWin({});
    }
</script> -->
</html>
